package fr.upmc.tps.mdoc.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.upmc.tps.mdoc.domain.DAOContactGroup;
import fr.upmc.tps.mdoc.domain.IDAOContactGroup;
import fr.upmc.tps.mdoc.models.ContactGroup;



/**
 * Servlet implementation class NewGroup
 */
public class NewGroup extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public NewGroup() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		request.getRequestDispatcher("/pages/newGroup.jsp").forward(request,
				response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		IDAOContactGroup daog = new DAOContactGroup();

		String groupName = request.getParameter("groupName");

		ContactGroup g = new ContactGroup();

		g.setGroupName(groupName);

		if (!daog.addGroup(g)) {
			System.out.println("Error: le groupe " + groupName
					+ "n'est pas crée");
		}

		request.getRequestDispatcher("/pages/addContact.jsp").forward(request,
				response);

	}

}
